<template>
    <el-dialog :title="!immunityForm.id ? '新增' : '修改'" :visible.sync="dialogVisible">
        <el-form ref="immunityForm" :model="immunityForm" :rules="immunityRules" label-width="100px">
            <el-row :gutter="20">
                <el-col :span="12">
                    <el-form-item label="加药日期" prop="date">
                        <el-date-picker
                                v-model="immunityForm.date"
                                type="date"
                                placeholder="加药日期"
                                style="width: 100%"
                        >
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="加药舍号" prop="shehao">
                        <el-input v-model="immunityForm.shehao" placeholder="加药舍号"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="加药头数" prop="sowInventory">
                        <el-input v-model="immunityForm.sowInventory" placeholder="加药头数"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="用药" prop="pigletInventory">
                        <el-input v-model="immunityForm.pigletInventory" placeholder="用药"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="用量（g)" prop="project">
                        <el-input v-model="immunityForm.project" placeholder="用量"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="控制方向" prop="project">
                        <el-input v-model="immunityForm.project" placeholder="控制方向"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="加药天数" prop="project">
                        <el-input v-model="immunityForm.project" placeholder="加药天数"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="加药用水量" prop="project">
                        <el-input v-model="immunityForm.project" placeholder="加药用水量"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="休药期" prop="project">
                        <el-input v-model="immunityForm.project" placeholder="休药期">
                            <template slot="append">天</template>
                        </el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="操作人" prop="project">
                        <el-input v-model="immunityForm.project" placeholder="操作人"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label="备注" prop="project">
                        <el-input type="textarea" v-model="immunityForm.project" placeholder="备注"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="submitForm('immunityForm')">确 定</el-button>
            </span>
    </el-dialog>
</template>

<script>
export default {
    data() {
        return {
            dialogVisible: false,
            immunityForm: {
                id: '',
            },
            immunityRules: {
                project: [
                    {required: true, message: this.$t('validate.required'), trigger: 'blur'}
                ],
            }
        }
    },
    methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if (!this.immunityForm.id) {
                        delete this.immunityForm.id
                    }
                    this.$http[!this.immunityForm.id ? 'post' : 'put'](`/a`, this.immunityForm).then((res) => {
                        if (res.code !== 0) {
                            return this.$message.error(res.msg);
                        }
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                        this.dialogVisible = false;
                        this.$emit('updateDialog')
                    })
                } else {
                    return false;
                }
            });
        },
    }
}
</script>


